package com.xzjt.web.service.impl;

import com.xzjt.web.entity.SysMenu;
import com.xzjt.web.entity.SysUser;
import com.xzjt.web.mapper.SysMenuMapper;
import com.xzjt.web.service.SysMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yuandong
 * @since 2021-11-11
 */
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {
    @Autowired
    private SysMenuMapper sysMenuMapper;


    @Override
    public List<SysMenu> selectList() {
        return this.sysMenuMapper.selectList(null);
    }


    /**
     * 根据角色id 查询对应的权限(菜单)
     * @param roleId
     * @return
     */
    public List<SysMenu> selectMenusByRoleId(Integer roleId){
        return this.sysMenuMapper.selectMenusByRoleId(roleId);
    }


    /**
     * 查询系统菜单列表
     *
     * @param userId 用户ID
     * @return 菜单列表
     */
    public List<SysMenu> selectMenuList(Integer userId){
        List<SysMenu> menuList = null;
        if (userId.equals(1)){
            //管理员查询所有
            menuList = sysMenuMapper.selectMenuList();
        }else {
            //普通用户查询所有
            menuList = sysMenuMapper.selectMenuListByUserId(userId);
        }
        return menuList;
    }

}
